<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二维码在线API测试</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            padding: 30px;
            background: #f5f5f5;
        }
        
        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        
        .input-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }
        
        input[type="text"] {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            box-sizing: border-box;
        }
        
        input[type="text"]:focus {
            border-color: #007bff;
            outline: none;
        }
        
        .button-group {
            text-align: center;
            margin: 20px 0;
        }
        
        button {
            padding: 12px 24px;
            margin: 0 10px;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        
        .btn-primary {
            background: #007bff;
            color: white;
        }
        
        .btn-primary:hover {
            background: #0056b3;
        }
        
        .btn-secondary {
            background: #6c757d;
            color: white;
        }
        
        .btn-secondary:hover {
            background: #545b62;
        }
        
        .qr-container {
            text-align: center;
            margin: 30px 0;
            padding: 20px;
            border: 2px dashed #ddd;
            border-radius: 8px;
            min-height: 250px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 6px;
            font-size: 14px;
        }
        
        .result.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .result.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .result.info {
            background: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔲 二维码生成测试</h1>
        
        <div class="input-group">
            <label for="qrText">输入二维码内容：</label>
            <input type="text" id="qrText" placeholder="请输入要生成二维码的内容" value="测试二维码内容 - 阿萨德哈卡">
        </div>
        
        <div class="button-group">
            <button class="btn-primary" onclick="generateQR()">生成二维码</button>
            <button class="btn-secondary" onclick="clearQR()">清空</button>
        </div>
        
        <div class="qr-container" id="qrContainer">
            <div style="color: #999;">点击"生成二维码"按钮开始测试</div>
        </div>
        
        <div id="result"></div>
    </div>

    <script>
        function generateQR() {
            var text = document.getElementById('qrText').value.trim();
            var container = document.getElementById('qrContainer');
            var result = document.getElementById('result');
            
            if (!text) {
                showResult('请输入要生成二维码的内容', 'error');
                return;
            }
            
            try {
                // 显示加载状态
                container.innerHTML = '<div style="color: #666;">正在生成二维码...</div>';
                result.innerHTML = '';
                
                // 使用在线API生成二维码
                var qrApiUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + encodeURIComponent(text);
                
                var img = new Image();
                img.onload = function() {
                    var imgHtml = '<div>';
                    imgHtml += '<img src="' + qrApiUrl + '" alt="二维码" style="width: 200px; height: 200px; border: 1px solid #ddd; border-radius: 4px;">';
                    imgHtml += '<div style="margin-top: 10px; font-size: 12px; color: #666;">扫描上方二维码获取内容</div>';
                    imgHtml += '</div>';
                    container.innerHTML = imgHtml;
                    
                    showResult('✅ 二维码生成成功！<br>内容: ' + text + '<br>时间: ' + new Date().toLocaleString(), 'success');
                };
                
                img.onerror = function() {
                    container.innerHTML = '<div style="color: #dc3545;">❌ 二维码生成失败<br>可能是网络问题或API不可用</div>';
                    showResult('❌ 在线API生成失败，请检查网络连接', 'error');
                };
                
                img.src = qrApiUrl;
                
            } catch (e) {
                console.error('二维码生成错误:', e);
                container.innerHTML = '<div style="color: #dc3545;">❌ 发生错误</div>';
                showResult('❌ 生成过程中发生错误: ' + e.message, 'error');
            }
        }
        
        function clearQR() {
            document.getElementById('qrContainer').innerHTML = '<div style="color: #999;">点击"生成二维码"按钮开始测试</div>';
            document.getElementById('result').innerHTML = '';
        }
        
        function showResult(message, type) {
            var result = document.getElementById('result');
            result.innerHTML = message;
            result.className = 'result ' + type;
        }
        
        // 监听回车键
        document.getElementById('qrText').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                generateQR();
            }
        });
        
        // 页面加载完成后自动测试
        window.onload = function() {
            showResult('📋 页面已加载，可以开始测试二维码生成功能', 'info');
        };
    </script>
</body>
</html> 